package com.kitking.mybroadcast;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import com.kitking.mybroadcast.broadcast.NetWorkChange;

public class MainActivity extends AppCompatActivity {
private IntentFilter intentFilter;
private NetWorkChange netWorkChange;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //动态注册要监听的广播
        intentFilter=new IntentFilter();//对应manifist.xml里面的那个intentFilter
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
       // intentFilter.addAction(Intent.ACTION_BATTERY_LOW);
       // intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
       // intentFilter.addDataScheme("package");//同静态注册里面的那个
        netWorkChange=new NetWorkChange();
        registerReceiver(netWorkChange,intentFilter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(netWorkChange);
    }
}